package com.example.shellshopping.YCB_settings;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.shellshopping.R;
import com.example.shellshopping.goods.TypeAdapter;
import com.example.shellshopping.goods.TypeBean;

import java.util.List;

public class YCBAboutGuizeAdapter extends BaseAdapter {
    Context context;
    int clickPos = 0;
    List<String> data;

    public YCBAboutGuizeAdapter(Context context, List<String> data) {
        this.context = context;
        this.data = data;
    }
    //设置被点击的位置
    public void setClickPos(int clickPos){
        this.clickPos = clickPos;
        notifyDataSetChanged();  //重新绘制页面
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        YCBAboutGuizeAdapter.VH vh = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.ycb_item_type,parent,false);
            vh = new YCBAboutGuizeAdapter.VH(convertView);
            convertView.setTag(vh);
        }else{
            vh = (YCBAboutGuizeAdapter.VH)convertView.getTag();
        }
        String newStr = data.get(position);
        vh.tv.setText(newStr);
        //点击后，背景颜色，文字颜色，竖线的出现和隐藏
        if (position == clickPos) {
            //convertView.setBackgroundResource(R.color.gray);
            vh.tv.setTextColor(0xffff69b4);
            vh.tv.setTextSize(16);
            //float lenth = vh.tv.getTextScaleX();
            vh.line.setText(vh.tv.getText()+"  ");
            vh.line.setVisibility(View.VISIBLE);
        }else{
            //convertView.setBackgroundResource(R.color.white);
            vh.tv.setTextColor(Color.GRAY);
            vh.line.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }

    class VH{
        TextView tv,line;
        public  VH(View v){
            tv = v.findViewById(R.id.ycb_item_type_tv);
            line = v.findViewById(R.id.ycb_item_type_line);
        }
    }
}
